package com.xgimi.defaultapp.view;

import com.xgimi.defaultapp.R;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * @author hailong.qiu
 */
public class DefualtAppItemView extends LinearLayout {

	public DefualtAppItemView(Context context) {
		super(context);
		init(context, null);
	}

	public DefualtAppItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context, attrs);
	}

	public DefualtAppItemView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context, attrs);
	}

	private void init(Context context, AttributeSet attrs) {
		View.inflate(context, R.layout.default_app_item, this);
		app_name_tv = (TextView) findViewById(R.id.app_name_tv);
		app_icon_iv = (ImageView) findViewById(R.id.app_icon_iv);
		no_default_tv = (TextView) findViewById(R.id.no_default_tv);
		default_set_lay = findViewById(R.id.default_set_lay);
	}

	private TextView app_name_tv;
	private ImageView app_icon_iv;
	private TextView no_default_tv;
	private View default_set_lay;

	private String mAppName = "";
	private Drawable mIconDrawable;
	private boolean isDefaultApp = false;

	public void setAppIcon(Drawable d) {
		this.mIconDrawable = d;
		app_icon_iv.setImageDrawable(this.mIconDrawable);
	}

	public void setAppName(String tx) {
		this.mAppName = tx;
		app_name_tv.setText(this.mAppName);
	}
	
	public void setDefaultApp(boolean is) {
		this.isDefaultApp = is;
		default_set_lay.setVisibility(View.GONE);
		no_default_tv.setVisibility(View.GONE);
		if (this.isDefaultApp) { 
			default_set_lay.setVisibility(View.VISIBLE);
		} else { 
			no_default_tv.setVisibility(View.VISIBLE);
		}
	}

}
